package com.example.edu.Controller;

import com.example.edu.Dto.*;
import com.example.edu.Entity.Course;
import com.example.edu.Entity.Document;
import com.example.edu.Service.DocumentService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/document")
public class DocumentController {
    @Resource
    DocumentService documentService;

    @PostMapping("/create")
    public Return create(HttpServletRequest httpServletRequest, @RequestBody DocumentCreateDtoG documentCreateData) {
        return documentService.create(httpServletRequest,documentCreateData);
    }

    @PostMapping("/getList")
    public Return getList(HttpServletRequest httpServletRequest, @RequestBody DocumentListDtoG documentListData) {
        return documentService.getList(httpServletRequest,documentListData);
    }

    @PostMapping("/getTags")
    public Return getTags(HttpServletRequest httpServletRequest, @RequestBody TagListDtoG tagListData){
        return documentService.getTags(httpServletRequest,tagListData);
    }

    @PostMapping("/get")
    public Return get(HttpServletRequest httpServletRequest, @RequestBody Document document){
        return documentService.get(httpServletRequest, document.getDocument_id());
    }

    @PostMapping("/getDocument")
    public ResponseEntity<org.springframework.core.io.Resource> getDocument(@RequestBody Document document){
        return documentService.getDocument(document);
    }

    @PostMapping("/delete")
    public Return delete(@RequestBody Document document) {
        return documentService.delete(document);
    }

    @PostMapping("/update")
    public Return update(@RequestBody DocumentUpdateDtoG documentUpdateData){
        return documentService.update(documentUpdateData);
    }

    @PostMapping("/save")
    public Return save(HttpServletRequest httpServletRequest,@RequestParam("document_id") int documentId,
                       @RequestParam("document_type") String documentType,
                       @RequestParam("picture_urls") String pictureUrls,
                       @RequestPart("document_body") MultipartFile documentBody){
        return documentService.save(httpServletRequest,documentId,documentType,pictureUrls,documentBody);
    }

    @PostMapping("/getStudent")
    public Return getStudent(HttpServletRequest httpServletRequest, @RequestBody Course courseId){
        return documentService.getStudent(httpServletRequest, courseId.getCourse_id());
    }

    @PostMapping("/viewTime")
    public Return viewTime(HttpServletRequest httpServletRequest, @RequestBody ViewTimeDtoG viewTimeData){
        return documentService.viewTime(httpServletRequest,viewTimeData);
    }

    @PostMapping("/like")
    public Return like(@RequestBody Document documentId){
        return documentService.like(documentId.getDocument_id());
    }

    @PostMapping("/collect")
    public Return collect(@RequestBody Document documentId){
        return documentService.collect(documentId.getDocument_id());
    }
}
